package com.hxit.huaxiamelongarden.task;

import com.hxit.huaxiamelongarden.service.HotSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @ClassName HotSearchTask
 * @description 定时任务类--刷新热搜
 * @Author 12694
 * @Date 2025/2/1 21:04
 * @Version 1.0
 **/
@Component
public class HotSearchTask {

    @Autowired
    private HotSearchService hotSearchService;  // 你的 Redis 操作服务类

    // 每天晚上 11 点执行
    @Scheduled(cron = "0 0 23 * * ?")
    public void refreshHotSearchData() {
        // 设置过期时间为 1 小时
        hotSearchService.setHotSearchTTL(1, TimeUnit.HOURS);
        System.out.println("Hot search data refreshed at 11 PM");
    }
}
